package com.yashi.springmvcjbpm.processTest;

import java.util.HashMap;
import java.util.Map;

import org.drools.core.impl.StatefulKnowledgeSessionImpl;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.manager.RuntimeEngine;
import org.kie.api.runtime.manager.RuntimeManager;
import org.kie.internal.runtime.manager.context.ProcessInstanceIdContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * This is a sample file to launch a process.
 */
public class ProcessRuleTest {
	@Autowired
	private static RuntimeManager runtimeManager;

	public static final void main(String[] args) {
		try {
			// load up the knowledge base
			ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
					"com/yashi/springmvcjbpm/processTest/drools-spring.xml");
			StatefulKnowledgeSessionImpl impl = (StatefulKnowledgeSessionImpl) context.getBean("ksession");
			KieBase kbase = impl.getKieBase();
			KieSession ksession = kbase.newKieSession();
			
			// set the parameters
			Map<String, Object> params = new HashMap<String, Object>();
			HelloProcessModel hpm = new HelloProcessModel();
			hpm.setCount(new Integer("3"));
			hpm.setUserlocation("NewYorkUser");
			params.put("hpm", hpm);
			ksession.startProcess("looptest777",params);
		
			ksession.fireAllRules();
			
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

	
}